package cn.aj.basic.controller;

import cn.aj.basic.service.ILoginAccountService;
import cn.aj.basic.tdo.LoginAccountDto;
import cn.aj.basic.tdo.PhoneBinderDto;
import cn.aj.basic.tdo.WeChatCodeDto;
import cn.aj.basic.utils.AjaxResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;


@RestController
@RequestMapping("/login")
public class LoginAccountController {
    @Autowired
    private ILoginAccountService loginAccountService;


    /**
    * @Title: loginAccount
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/26 0026 13:31
    * @Parameters: [loginAccountDto]
    * @Return cn.aj.basic.utils.AjaxResultUtil
     * 账户登录
    */
    @PostMapping("/account")
    public  AjaxResultUtil loginAccount(@RequestBody @Valid LoginAccountDto loginAccountDto) {
        // 返回账号,密码
           Map<String, Object> map =  loginAccountService.loadAccount(loginAccountDto);
            return AjaxResultUtil.getAjaxResult().success().setResultObj(map);
    }

    /**
    * @Title: loginAccount
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/27 0027 21:10
    * @Parameters: [loginAccountDto]
    * @Return cn.aj.basic.utils.AjaxResultUtil
     * 微信登录
    */
    @PostMapping("/wechat")
    public  AjaxResultUtil loginWechat(@RequestBody @Valid WeChatCodeDto weChatCodeDto) {
        return loginAccountService.loginWechat(weChatCodeDto);
    }

    /**
    * @Title: loginBinder
    * @Description: TODO
    * @Author: Mr.GT
    * @Version: 1.0
    * @Date:  2022/11/27 0027 23:38
    * @Parameters: [weChatCodeDto]
    * @Return cn.aj.basic.utils.AjaxResultUtil
     * 手机绑定
    */
    @PostMapping("/binder")
    public  AjaxResultUtil loginBinder(@RequestBody @Valid PhoneBinderDto phoneBinderDto) {
        Map<String, Object> map = loginAccountService.loginBinder(phoneBinderDto);
        return AjaxResultUtil.getAjaxResult().success().setResultObj(map);
    }
}